<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客注册页</title>

    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">

</head>

<body>
<div class="nav">
    <img src="https://tse3-mm.cn.bing.net/th/id/OIP-C.wb9I_pEZGVG3RIQtuLCXNQHaHZ?w=181&h=180&c=7&r=0&o=7&dpr=1.3&pid=1.7&rm=3" alt="">
    <span class="blog-title">我的博客系统</span>
    <div class="space"></div>
    <a class="nav-span" href="blog_list.html">主页</a>
    <a class="nav-span" href="blog_edit.html">写博客</a>
    <a class="nav-span" href="blog_login.html">登录</a>
</div>

<div class="container-login">
    <div class="login-dialog">
        <h3>注册</h3>
        <div class="row">
            <span>用户名</span>
            <input type="text" name="username" id="username">
        </div>
        <div class="row">
            <span>密码</span>
            <input type="password" name="password" id="password">
        </div>
        <div class="row">
            <span>GitHub地址</span>
            <input type="githuburl" name="githuburl" id="githuburl">
        </div>
        <div class="row">
            <button id="submit" onclick="logon()">提交</button>
        </div>

    </div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/common.js"></script>
<script>
    function logon(){
        var username = $("#username").val();
        var password = $("#password").val();
        var githuburl = $("#githuburl").val();
        if(username == "" || password == ""){
            alert("请填写完整信息");
            return;
        }
        $.ajax({
            type: "POST",
            url: "/user/register",
            data: {
                userName: username,
                password: password,
                githubUrl: githuburl
            },
            success: function (data) {
                if(data.code == "Success"){
                    alert("注册成功");
                    window.location.href = "blog_login.html";
                }else{
                    console.log(data);
                    alert(data.errMessage);
                }
            },
            error: function (data) {
                console.log(data);
                alert("注册失败");
            }
        })
    }

</script>
</body>

</html>